#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 2e5 + 10;
const int MOD = 1e9 + 7;

vector<int> g[MAXN];
int a[MAXN];

int t, n, k, x;
void clear_graph() {
    for (int i = 1; i <= n; i++) {
        g[i].clear();
    }
    x = 0;
}

int p, fp;

int dp[MAXN];
bool dfs(int u, int fa = -1) {
    dp[u] = a[u];
    bool temp = false;
    for (auto v : g[u]) {
        if (v != fa && v != -1) {
            temp |= dfs(v, u);
            dp[u] ^= dp[v];
        }
    }

    if (dp[u] == x && p == -1) p = u, fp = fa;
    return temp || dp[u] == x;
}

bool check() {
    p = fp = -1;
    if (!dfs(1)) {
        return false;
    }
    // cout << p << ',' << fp << endl;
    if (p == -1 || fp == -1)
        return false;
    for (auto& v : g[p]) {
        if (v == fp) {
            v = -1;
        }
    }

    for (auto& v : g[fp]) {
        if (v == p) {
            v = -1;
        }
    }
    p = fp = -1;
    return dfs(1);
    // cout << p << ',' << fp << endl;
}
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> t;
    while (t--) {
        cin >> n >> k;
        clear_graph();

        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            x ^= a[i];
        }
        int u, v;
        for (int i = 1; i <= n - 1; i++) {
            cin >> u >> v;
            g[u].push_back(v);
            g[v].push_back(u);
        }

        if (x == 0) {
            puts("YES");
            continue;
        }

        bool flag = check();
        if (flag && k >= 3) puts("YES");
        else puts("NO");
    }
    return 0;
}